package com.example.lin.start;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @className: ExcelSys
 * @description:
 * @author: Lin.Gu
 * @date: 2024/6/14
 */
public class ExcelSys {
    public static void main(String[] args) {
        try {
            // 创建第一个Excel文件
            Workbook workbook1 = new XSSFWorkbook();
            Sheet sheet1 = workbook1.createSheet("Sheet1");
            //第一行
            Row row1 = sheet1.createRow(0);
            //第一行 第一列
            Cell cell1 = row1.createCell(0);
            cell1.setCellValue("Hello from Excel 0");

            //第一行 第二列
            Cell cell2 = row1.createCell(1);
            cell2.setCellValue("Hello from Excel 1");

            // 保存第一个Excel文件到临时位置
            String tempFile1 = "D:\\test\\temp_excel1.xlsx";
            FileOutputStream outputStream1 = new FileOutputStream(tempFile1);
            workbook1.write(outputStream1);
            workbook1.close();
            outputStream1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
